/*
 * analog_digital.c
 *
 *  Created on: Oct 8, 2011
 *  Author: Mario H. Voorsluys
 *	email: forcaeluz@gmail.com
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, visit:
 * http://www.gnu.org/copyleft/gpl.html
 */

#include "analog_digital.h"

void init_adc(){
	ADCSRA = (1 << ADEN);
	ADMUX = (1 << REFS0);
}

int adc_value(int id){
	int value = 0;
	ADMUX |= (id<<MUX0);
	ADCSRA |= (1 << ADSC);
	while (!(ADCSRA & (1 << ADIF)));
	value = ADCL + (ADCH << 8);
	ADCSRA |= (1 << ADIF);			// clear ADCIF
	value = ADCL + (ADCH << 8);
	return value;
}
